function getFormDatatoJson(formId) {
    var dataJson = {};
    $("#"+formId).serializeArray().map(function (x) {
        if (dataJson[x.name ] !== undefined) {
            if (!dataJson[x.name].push) {
                dataJson[x.name] = [dataJson[x.name]];
            }
            dataJson[x.name].push(x.value || '');
        } else {
            dataJson[x.name] = x.value || '';
        }
    });
    return dataJson;
}
function testaaa(){
	alert("testaaa");
}

function changProject(id){
     changeMain("ietm-home?"+id);
}
$(function(){
			adaptive();
			renderICkeck();
			param={};
			pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'},param);
				//项目新增
				$('#project-add').click(function(e){

			        e.preventDefault();
			        var diag = new $.Zebra_Dialog({
			            source: {'iframe': {
			            					'id':'padd',
			                				'src':'project-add.html',
			                				'height':400,
			            }},
			            width:600,
			            title:'新增项目',
			            buttons: [
					               {caption: '保存', callback: function() { 
					            	   
					            	   var opts = {
					            			     lines: 13, // loading小块的数量
					            			     length: 7, // 小块的长度
					            			     width: 4, // 小块的宽度
					            			     radius: 20, // 整个圆形的半径
					            			     corners: 1, // 小块的圆角，越大则越圆
					            			     rotate: 0, // loading动画的旋转度数，貌似没什么实际作用
					            			     color: '#000', // 颜色
					            			     speed: 1, // 变换速度
					            			     trail: 60, // 余晖的百分比
					            			     shadow: false, // 是否渲染出阴影
					            			     hwaccel: false, // 是否启用硬件加速
					            			     className: 'spinner', // 给loading添加的css样式名
					            			     zIndex: 2e9, // The z-index (defaults to 2000000000)
					            			     top: 'auto', // Top position relative to parent in px
					            			     left: 'auto' // Left position relative to parent in px
					            			};
					            			  
					            			 var target = document.getElementById('foo');
					            			 //初始化spin-初始化函数中
					            			 var spinner = new Spinner(opts);//建议将spinner作为全局变量，以方便后面的调用。
					            			  
					            			 //显示进度动画
					            			 spinner.spin(target);
					            			  
					            			 $("#hbg").show();
					            	     var doc= document.getElementById("padd").contentWindow.getFormDatatoJson("addForm");
					            	     $.ajax({
					            	            url: '/ietm/project/saveOrUpdate',
					            	            type: 'post',
					            	            dataType:'json',
					            	            data: doc,
								    		    success: function (data) {
							            			 //隐藏进度动画
							            			 spinner.stop();//原文中未提及
								    		    	if(data.flag==="true"){
									    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传成功!</div></div>', {
									    			            'title':'提示',
									    			            'buttons':  [
									    		                    {caption: '确定', callback: function() {
									    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
									    		                    		  adaptive();
									    		                  			  renderICkeck();
									    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
													    		  	    });
									    		                    }}
									    		                ]
									    			         });
									    		  	    
								    		    	}else if(data.flag==="isHave"){
									    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">项目已存在!</div></div>', {
									    			            'title':'提示',
									    			            'buttons':  [
									    		                    {caption: '确定', callback: function() {
									    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
									    		                    		  adaptive();
									    		                  			  renderICkeck();
									    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
													    		  	    });
									    		                    }}
									    		                ]
									    			         });
								    		    	}else if(data.flag==="isNotZip"){
									    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传的不是zip文件!</div></div>', {
									    			            'title':'提示',
									    			            'buttons':  [
									    		                    {caption: '确定', callback: function() {
									    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
									    		                    		  adaptive();
									    		                  			  renderICkeck();
									    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
													    		  	    });
									    		                    }}
									    		                ]
									    			         });
								    		    	}else if(data.flag==="false"){
									    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">压缩包中不存在项目文件!</div></div>', {
									    			            'title':'提示',
									    			            'buttons':  [
									    		                    {caption: '确定', callback: function() {
									    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
									    		                    		  adaptive();
									    		                  			  renderICkeck();
									    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
													    		  	    });
									    		                    }}
									    		                ]
									    			         });								    		    		
								    		    	}
								    		     },
								    		     error: function (data) {
								    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">上传失败!</div></div>', {
								    			            'title':'提示',
								    			            'buttons':  [
								    		                    {caption: '确定', callback: function() {
								    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
								    		                    		  adaptive();
								    		                  			  renderICkeck();
								    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
												    		  	    });
								    		                    }}
								    		                ]
								    			         });
								    		     }
					            	        });
					                  }
					               }
			                        ]
			        });
			    
				});

				//项目编辑
				$('#project-edit').on('click', function(e) {
			        e.preventDefault();
			        var ch =$(".table-project .table-projectl input:checked");
			        var len=ch.length; 
			        var id="";
			        if(len===1){
			        	$(".table-project .table-projectl input:checked").each(function(index){
		  					id= $(this).attr("value");
			        	});
			  			var diag = new $.Zebra_Dialog({
						    source: {'iframe': {
						            		'id':'pedit',
						               		'src':'/ietm/project/getObject?id='+id+"&page=project-edit" ,
						                	'height':400,
						            }},
						            width:600,
						            title:'编辑',
						            buttons:[
								               {caption: '保存', callback: function() { 
								            	   var doc= document.getElementById("pedit").contentWindow.getFormDatatoJson("editForm");
								            	     $.ajax({
								            	            url: '/ietm/project/saveOrUpdate',
								            	            type: 'post',
								            	            dataType:'text',
								            	            data: doc,
											    		    success: function (data) {
											    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
											    			            'title':'提示',
											    			            'buttons':['确定']
											    			         });
											    		    	 $("#frameReft").load("/ietm/project?random="+Math.random());
											    		     },
											    		     error: function (data) {
											    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
											    			            'title':'提示',
											    			            'buttons':['确定']
											    			         });
											    		     }
								            	        });
								                  }
								               }
						                        ]
						        });
			        	
			        }else
			        	{
	    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">请选择一条数据进行编辑!</div></div>', {
	    			            'title':'提示',
	    			            'buttons':['确定']
	    			         });
			        	}
			    });
				//项目删除
				$('#project-delete').on('click', function(e) {
					alert("dddd");
			        e.preventDefault();
			        var ch =$(".table-project .table-projectl input:checked");
			        var len=ch.length; 
			        var ids="";
			        if(len>0){
			        	$(".table-project .table-projectl input:checked").each(function(index){
			  				if(len-1>index){
		  					ids += $(this).attr("value")+",";
		  				}else{
		  					ids += $(this).attr("value");
		  				}
			        	});
			     		 $.ajax({
			    		     type: "post",
			    		     dataType: "text",
			    		     url:'/ietm/project/delete',
			    		     data:{'ids':ids},
			    		     success: function (data, status) {
			    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
			    			            'title':'提示',
			    			            'buttons':['确定']
			    			         });
			    		    	 projectId="";
			    		    	 $("#frameReft").load("/ietm/project?random="+Math.random());
			    		     },
			    		     error: function (data) {
			    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
			    			            'title':'提示',
			    			            'buttons':['确定']
			    			         });
			    		     }
			    		 });			        	
			        }else
			        	{
	    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">请选中数据再进行删除操作!</div></div>', {
	    			            'title':'提示',
	    			            'buttons':['确定']
	    			         });
			        	}
			    });
				//项目更新
				$('#project-update').on('click', function(e) {
			        e.preventDefault();
			        var ch =$(".table-project .table-projectl input:checked");
			        var len=ch.length;
			        var id="";
			        if(len===1){
			        	$(".table-project .table-projectl input:checked").each(function(index){
			        		id=$(this).attr("value")
			        	});
			  			var diag = new $.Zebra_Dialog({
						    source: {'iframe': {
						            		'id':'pupdate',
						               		'src':'/ietm/project/getObject?id='+id+"&page=project-update" ,
						                	'height':80,
						            }},
						            width:400,
						            title:'更新',
						            buttons:[
								               {caption: '保存', callback: function() { 
								            	   var opts = {
								            			     lines: 13, // loading小块的数量
								            			     length: 7, // 小块的长度
								            			     width: 4, // 小块的宽度
								            			     radius: 20, // 整个圆形的半径
								            			     corners: 1, // 小块的圆角，越大则越圆
								            			     rotate: 0, // loading动画的旋转度数，貌似没什么实际作用
								            			     color: '#000', // 颜色
								            			     speed: 1, // 变换速度
								            			     trail: 60, // 余晖的百分比
								            			     shadow: false, // 是否渲染出阴影
								            			     hwaccel: false, // 是否启用硬件加速
								            			     className: 'spinner', // 给loading添加的css样式名
								            			     zIndex: 2e9, // The z-index (defaults to 2000000000)
								            			     top: 'auto', // Top position relative to parent in px
								            			     left: 'auto' // Left position relative to parent in px
								            			};
								            			  
								            			 var target = document.getElementById('foo');
								            			 //初始化spin-初始化函数中
								            			 var spinner = new Spinner(opts);//建议将spinner作为全局变量，以方便后面的调用。
								            			  
								            			 //显示进度动画
								            			 spinner.spin(target);
								            			 $("#hbg").show();
								            	   var doc= document.getElementById("pupdate").contentWindow.getFormDatatoJson("updateForm");
								            	     $.ajax({
								            	            url: '/ietm/project/saveOrUpdate',
								            	            type: 'post',
								            	            dataType:'json',
								            	            data: doc,
											    		    success: function (data) {
											    		    	if(data.flag==="true"){
											    		 			 //隐藏进度动画
											            			 spinner.stop();//原文中未提及
												    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">更新成功!</div></div>', {
												    			            'title':'提示',
												    			            'buttons':[
														    		                    {caption: '确定', callback: function() {
														    		                    	  $("#frameReft").load("/ietm/project?random="+Math.random(),function(response){
														    		                    		  adaptive();
														    		                  			  renderICkeck();
														    		                    		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
																		    		  	    });
														    		                    }}
														    		                ]	
												    		    	 });
											    		    	}else if(data.flag==="nSame"){
												    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传的文件与要更新的项目不相同!</div></div>', {
												    			            'title':'提示',
												    			            'buttons':['确定']
												    			         });
											    		    	}else if(data.flag==="isNotZip"){
												    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传的不是zip文件!</div></div>', {
												    			            'title':'提示',
												    			            'buttons':['确定']
												    			         });
											    		    	}else if(data.flag==="false"){
												    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">压缩包中不存在项目文件!</div></div>', {
												    			            'title':'提示',
												    			            'buttons':['确定']
												    			         });								    		    		
											    		    	}
											    		     },
											    		     error: function (data) {
											    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">更新失败!</div></div>', {
											    			            'title':'提示',
											    			            'buttons':['确定']
											    			         });
											    		     }
								            	        });
								                  }
								               }
						                        ]
						        });
			        	
			        }else
			        	{
	    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">请选择一个项目进行更新!</div></div>', {
	    			            'title':'提示',
	    			            'buttons':['确定']
	    			         });
			        	}
			    });
				
				$('#projectSearch').click(function(){
			 		$("#frameReft").load("/ietm/project",{'pmTitle': $("#pmTitle").val()});
			 		  $('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'project'}));
				});
				//渲染分页工具条
				 ;
	    	});